package com.servlet;

import com.entity.User;
import com.opensymphony.xwork2.ActionSupport;
import com.service.BaseService;
import com.service.impl.BaseServiceImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/7/22.
 */
public class Login extends ActionSupport {
    static BaseService baseService = new BaseServiceImpl();
    private User user;
    private String msg;
    private List<User> users;

    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public String execute() throws Exception {
        User login = baseService.login(user.getUserName(), user.getUserPassword());
        if (login != null) {
            return SUCCESS;
        } else {
            msg = "密码或用户名错误";
            return ERROR;
        }
    }

    public String register() throws Exception {
        User user1 = new User(1, "admin", "123");
        User user2 = new User(2, "测试", "123");
        User user3 = new User(3, "张三", "123");
        users = new ArrayList<User>();
        users.add(user1);
        users.add(user2);
        users.add(user3);
        System.out.println(1);
        return SUCCESS;
    }
}
